{{extend "layout_admin.html"}}

{{block css}}
{{end}}

{{block title}}
<i class="fa fa-bug fa-fw"></i> BUG 详细信息
{{end}}

{{block content}}
<div class="row">
  <div class="col-lg-12">
    <form role="form" class="form-horizontal">
      <div class="form-group">
        <div class="col-lg-offset-2 col-lg-10">
            <button class="btn btn-link" id="btn-back" type="button"> 返回</button>
        </div>
      </div>

      <div class="form-group">
        <label class="col-lg-2 control-label">标题</label>
        <div class="col-lg-6">
          <input type="text" class="form-control" value="{{=bug_title}}" readonly>
        </div>
      </div>
      
      <div class="form-group">
        <label class="col-lg-2 control-label">所属项目</label>
        <div class="col-lg-2">
            <input type="text" class="form-control" value="{{=bug_project}}" readonly>
        </div>
        
        <label class="col-lg-2 control-label">严重性</label>
        <div class="col-lg-2">
            <input type="text" class="form-control" value="{{=bug_importance}}" readonly>
        </div>
      </div>
      
      <div class="form-group">
        <label class="col-lg-2 control-label">分派给</label>
        <div class="col-lg-2">
            <input type="text" class="form-control" value="{{=assigned_user}}" readonly>
        </div>

        <label class="col-lg-2 control-label">状态</label>
        <div class="col-lg-2">
            <input type="text" class="form-control" value="{{=bug_state}}" readonly>
        </div>
      </div>
            
      <div class="form-group">
        <label class="col-lg-2 control-label">BUG 描述</label>
        <div class="col-lg-6">
          <textarea class="form-control" rows="6" readonly>{{=bug_desc}}</textarea>
        </div>
      </div>

      {{for c in comments:}}
      <div class="form-group">
          <label class="col-lg-2 control-label">BUG 备注
              <br>{{=c.create_user.name}}
              <br>{{=c.create_time.strftime("%Y-%m-%d %H:%M:%S")}}
          </label>
        <div class="col-lg-6">
            <textarea class="form-control" rows="4" readonly>{{=c.comment}}</textarea>
        </div>
      </div>
      {{pass}}

      <div class="form-group">
          <div class="col-lg-offset-2 col-lg-6">
              <table class="table table-striped" id="tb-attachments">
                  <thead>
                      <th>#</th>
                      <th>文件名</th>
                      <th>下载</th>
                  </thead>
                  <tbody>
                      {{order = 1}}
                      {{for ba in bug_attachments:}}
                      <tr>
                          <td>{{=order}}</td>
                          <td>{{=ba.name}}</td>
                          <td><button type="button" class="btn btn-link" onclick="download_attachment({{=ba.id}});"><i class="fa fa-download fa-fw"></i> 下载</button></td>
                      </tr>
                      {{pass}}
                  </tbody>
              </table>
          </div>
      </div>
      
    </form>
  </div> <!-- col-lg-12 -->
</div>   <!-- row -->
<hr>
<h3>BUG 修改履历: </h3>
<div class="row">
    <div class="col-lg-offset-2 col-lg-6">
        <table class="table table-striped">
            <thead>
                <th>#</th>
                <th>FROM</th>
                <th>TO</th>
                <th>状态</th>
                <th>严重性</th>
                <th>更新时间</th>
            </thead>
            <tbody>
                {{order = 1}}
                {{for bh in bug_histories:}}
                <tr>
                    <td>{{=order}}</td>
                    <td>{{=bh.assign_from_user.real_name}}</td>
                    <td>{{=bh.assign_to_user.real_name}}</td>
                    <td>{{=bh.bug_state.name}}</td>
                    <td>{{=bh.bug_importance.name}}</td>
                    <td>{{=bh.update_time.strftime("%Y-%m-%d %H:%M:%S")}}</td>
                </tr>
                {{order += 1}}
                {{pass}}
            </tbody>
        </table>
    </div>
</div>
{{end}}

{{block js}}
<script type="text/javascript">
    $(function(){
        $("#btn-back").click(function(){
            location.href = "/admin/bug-list";
        });
    });

  /* 下载已经上传的附件 */
  function download_attachment(ba_id)
  {
      location.href = "/bug/download-attachment/" + ba_id;
  }
</script>
{{end}}
